import { defineStore } from 'pinia';
import { orgLogin,userInfoData } from '@/request/api';
export const useUserStore = defineStore('user', {
  state: () => ({
    token: null,
	name: '',
	userId: '',

  }),
  actions: {
    login(params) {
		orgLogin(params).then((res)=>{
			this.token = res.info
			if(this.token){
				this.getUserInfo(this.token)
				
			}
		})
    },
	getUserInfo(token){
		userInfoData(token).then((res)=>{
			console.log('token',res.info);
			this.name = res.info.name
			this.userId = res.info.id
			uni.navigateTo({
				url:'/pages/index/index'
			})
		})
	}
  },
  persist: true, // 简单启用，使用默认配置
  // 或者使用更详细的配置
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'userInfo',
        storage: localStorage,
        paths: ['token', 'name','userId'] // 只持久化特定字段
      }
    ]
  }
});